module hazard(
        input   [ 3:0]  i_cond,
        input           i_condpass,
        input   [14:0]  i_condpass_read_gpr_ex1,
        input           i_condpass_read_nzcv_ex1,
        input           i_condpass_read_mode_ex1,
        input           i_condpass_read_spsr_ex1,
        input   [14:0]  i_gpr_we_ex2,
        input   [14:0]  i_gpr_we_ex3,
        input   [14:0]  i_gpr_we_wb,
        input           i_nzcv_we_ex2,
        input           i_nzcv_we_ex3,
        input           i_nzcv_we_wb,
        input           i_mode_we_ex2,
        input           i_mode_we_ex3,
        input           i_mode_we_wb,
        input           i_spsr_we_ex2,
        input           i_spsr_we_ex3,
        input           i_spsr_we_wb,
        output          o_nohazard
);

wire    [14:0]  read_gpr_ex1;
wire            read_nzcv_ex1;
wire            read_mode_ex1;
wire            read_spsr_ex1;

wire hazard_gpr;
wire hazard_nzcv;
wire hazard_mode;
wire hazard_spsr;

assign read_gpr_ex1 = {15{i_condpass}} & i_condpass_read_gpr_ex1;
assign read_nzcv_ex1 = ~&i_cond[3:1] | i_condpass & i_condpass_read_nzcv_ex1;
assign read_mode_ex1 = i_condpass & i_condpass_read_mode_ex1;
assign read_spsr_ex1 = i_condpass & i_condpass_read_spsr_ex1;

assign hazard_gpr = |(read_gpr_ex1 & ( i_gpr_we_ex2 | i_gpr_we_ex3 | i_gpr_we_wb ));
assign hazard_nzcv = read_nzcv_ex1 & ( i_nzcv_we_ex2 | i_nzcv_we_ex3 | i_nzcv_we_wb );
assign hazard_mode = read_mode_ex1 & ( i_mode_we_ex2 | i_mode_we_ex3 | i_mode_we_wb );
assign hazard_spsr = read_spsr_ex1 & ( i_spsr_we_ex2 | i_spsr_we_ex3 | i_spsr_we_wb );

assign o_nohazard = ~( hazard_gpr | hazard_nzcv | hazard_mode | hazard_spsr );

endmodule
